using System;
using System.Net.Mail;
using Edge.Common.Utils;
using Edge.Common.Utils;

namespace Edge.Common.Mail.Impl
{
    public class DefaultFromInterceptor
    {
        private readonly string defaultFrom;


        public DefaultFromInterceptor(string from)
        {

            if (StringUtils.IsBlankOrNull(from))
                throw new ArgumentException("defaultFrom");

            this.defaultFrom = from;
        }

        public void Intercept(object sender, SendMailEventArgs args)
        {
            MailMessage message = args.MailMessage;
            if (message.From == null || StringUtils.IsBlankOrNull(message.From.Address))
            {
                message.From = new MailAddress(defaultFrom);
            }
        }
    }
}